// phamnamlong(C) 2011

#include <cstdio>
#include <string.h>

using namespace std;

int a[501][501];
int lastRow, lastCol[501];
bool win[501][501];
int ntest, n;

bool even(int x)
{
	return (x % 2 == 0);
}

int main()
{
	scanf("%d", &ntest);
	while (0 < ntest--)
	{
		// input
		scanf("%d", &n);
		for (int i = 1; i <= n; i++) 
		for (int j = 1; j <= n; j++) 
			scanf("%d", &a[i][j]);

		// initialisation
		lastRow = 0;
		memset(lastCol, 0, sizeof(lastCol));
		for (int i = 0; i <= n; i++) 
		{
			win[0][i] = false;
			win[i][0] = false;
		}

		for (int i = 1; i <= n; i++)
		{
			lastRow = 0;
			for (int j = 1; j <= n; j++)
			{
				lastRow = (lastRow + a[i][j]) % 2;
				lastCol[j] = (lastCol[j] + a[i][j]) % 2;
				win[i][j] = (!win[i-1][j] && even(lastRow)) || (!win[i][j-1] && even(lastCol[j]));
			}
		}
		
		// output
		if (win[n][n]) printf("YES\n");
		else printf("NO\n");
	}


	return 0;
}
